package com.fecean.aabbc.netty.server.controller;

import com.fecean.aabbc.netty.server.init.ClientChannel;
import io.netty.channel.Channel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {

    @Resource
    private ClientChannel clientChannel;

    @GetMapping("/test")
    public String test(@RequestParam("text") String text){
        Channel channel = clientChannel.getClientChannel("abc");
        if(channel != null && text != null){
            channel.writeAndFlush(text);
        }
        return "TestController.test.text = " + text;
    }

    @GetMapping("/size")
    public int size(){
        return clientChannel.getSize();
    }
}
